home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8000 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: [Q] Help. Initializing crashes program!!!
  5. Date: 28 Feb 1996 13:06:02 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4h2g3qINN1kk@anvil.ugrad.cs.ubc.ca>
  8. References: <1996Feb28.084428.1@debbie.ee.queensu.ca>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <1996Feb28.084428.1@debbie.ee.queensu.ca>,
  12.  <majeed@qucdntri.ee.queensu.ca> wrote:
  13.  >Hello.
  14.  >
  15.  >Alright, here's are some definitions:
  16.  >
  17.  >#define N 8
  18.  >#define L 13
  19.  >
  20.  >typedef struct
  21.  >{
  22.  >    float I[L],Q[L];
  23.  >} f_short_array;
  24.  >
  25.  >Here's a subroutine:
  26.  >void PROC1(void)
  27.  >{
  28.  >    int m,j;
  29.  >    ... (other declarations)
  30.  >    static f_short_array poly_reg[N];
  31.  >
  32.  >/* initializing */
  33.  >    for (m = 0; m < N; m++)
  34.  >    {
  35.  >        for (j = 0; j < L; j++)
  36.  >        {
  37.  >            poly_reg[m].I[j] = 0.0;
  38.  >            poly_reg[m].Q[j] = 0.0;
  39.  >        }
  40.  >    }
  41.  
  42. [ snip ]
  43.  
  44.  >Why is it that if I leave the initialization as above, the program crashes
  45.  
  46. The initialization should have no effect, since the struct array is static, and
  47. static floats will be initialized to 0.0 if they don't have explicit
  48. initializers.
  49.  
  50. The only effect of including the initialization code as opposed to not
  51. including it is that after the loops, the variable m contains N, and j contains
  52. L.
  53.  
  54. Does the subsequent code depend on the values of m or j? Does any of the code
  55. access past the array bounds or invoke any other sort of undefined behavior?
  56.  
  57. If not, your compiler or linker is broken.
  58. -- 
  59.  
  60.